Skip to content

Skip plugin entirely in production builds - #5

Merged
Peyton-Spencer merged 2 commits into
mainfrom
fix/skip-production-builds
Feb 24, 2026
Merged

Skip plugin entirely in production builds#5
Peyton-Spencer merged 2 commits into
mainfrom
fix/skip-production-builds

Conversation

@Peyton-Spencer

@Peyton-Spencer Peyton-Spencer commented Feb 24, 2026

Copy link
Copy Markdown
Contributor

Summary

• Added apply: "serve" to the Vite plugin config so the entire plugin is excluded from production builds
• Removed the now-unnecessary isDev guard from transform/transformIndexHtml hooks
• Updated tests to verify the plugin metadata instead of testing dead code paths

Problem

During vite build, Rolldown was calling into solid-grab's transform hook for all 2541 modules. Even though it returned null immediately for production mode, the cumulative overhead of these calls made the plugin consume 90% of build time:

[PLUGIN_TIMINGS] Warning: Your build spent significant time in plugins. Here is a breakdown:
  - solid-grab (90%)
  - solid (9%)

Fix

Vite's apply: "serve" option tells Vite to completely skip the plugin during vite build. No hooks are called at all — the plugin simply doesn't exist in the build pipeline.

Test plan

  • All 59 existing tests pass
  • Verify vite build no longer shows solid-grab in PLUGIN_TIMINGS

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • Refactor

    • Improved plugin initialization for development mode to enhance consistency and reliability.
  • Tests

    • Updated test suite to reflect refined plugin behavior.

The plugin was consuming 90% of build time during `vite build` because
Rolldown called into the transform hook for every module, even though
it returned null immediately. Using Vite's `apply: "serve"` option
removes the plugin entirely from the build pipeline in production,
eliminating all hook call overhead.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Feb 24, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@Peyton-Spencer has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 7 minutes and 37 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 2548ef1 and ba86686.

📒 Files selected for processing (1)
  • tests/vite-plugin.test.ts
📝 Walkthrough

Walkthrough

The plugin now explicitly restricts execution to development mode by adding apply: "serve" to its configuration, eliminating the internal isDev flag that previously guarded the transform and HTML injection logic. Tests are updated to validate serve-mode behavior.

Changes

Cohort / File(s) Summary
Plugin Configuration
src/vite.ts
Added apply: "serve" to limit plugin execution to development/serve mode. Removed isDev flag computation and conditional guards from configResolved, transform, and transformIndexHtml hooks, allowing transforms to run unconditionally when applicable.
Test Updates
tests/vite-plugin.test.ts
Refactored tests to verify serve-mode behavior by asserting plugin.apply === "serve" instead of testing production-mode scenarios. Maintains existing JSX and data attribute test coverage.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 The plugin hops lighter now,
No more isDev to figure out—
Vite's "serve" flag takes the lead,
Transforms run free without the creed.
Cleaner code, a simpler way,
Dev-mode hooks save the day! 🌱

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Skip plugin entirely in production builds' directly and clearly summarizes the main change: adding apply: 'serve' to exclude the plugin from production builds.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/skip-production-builds

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (3)
tests/vite-plugin.test.ts (3)

76-80: Duplicate apply assertion — consolidate into the plugin metadata describe block.

This test (and its twin at line 252) only asserts plugin.apply === "serve" — it's testing plugin metadata, not transform or transformIndexHtml behaviour. Having the same one-liner assertion in two different describe blocks adds noise without coverage benefit.

♻️ Suggested consolidation

Remove lines 76–80 and 252–256, and add a single test to the plugin metadata describe block:

 describe("plugin metadata", () => {
   test("has correct name", () => {
     const plugin = solidGrab();
     expect(plugin.name).toBe("solid-grab");
   });

   test("enforces pre", () => {
     const plugin = solidGrab();
     expect(plugin.enforce).toBe("pre");
   });
+
+  test("applies only during serve (skipped in production builds)", () => {
+    const plugin = solidGrab();
+    expect(plugin.apply).toBe("serve");
+  });
 });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/vite-plugin.test.ts` around lines 76 - 80, Remove the duplicate
one-line tests that only assert plugin.apply === "serve" (the test named "skips
in production mode (apply: serve)" and its twin) and instead add a single
assertion inside the existing "plugin metadata" describe block that checks the
plugin metadata once; locate the creation of the plugin via solidGrab() and
place expect(plugin.apply).toBe("serve") in that metadata block so metadata
checks are consolidated and the redundant tests are deleted.

6-21: mode parameter in createPlugin is now vestigial.

configResolved only reads config.root after the isDev removal. The command and mode fields injected into fakeConfig are passed to the hook but never consumed, making the mode parameter a no-op that could mislead future contributors into thinking production-mode behaviour can still be exercised through this helper.

♻️ Suggested simplification
 function createPlugin(
   options: Parameters<typeof solidGrab>[0] = {},
-  mode: "development" | "production" = "development"
 ): Plugin {
   const plugin = solidGrab(options);

-  const fakeConfig = {
-    root: "/project",
-    command: mode === "development" ? "serve" : "build",
-    mode,
-  } as ResolvedConfig;
+  const fakeConfig = { root: "/project" } as ResolvedConfig;

   (plugin as any).configResolved(fakeConfig);
   return plugin;
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/vite-plugin.test.ts` around lines 6 - 21, The createPlugin helper has a
vestigial mode parameter and populates fakeConfig.command and fakeConfig.mode
which configResolved no longer consumes; remove the mode parameter from
createPlugin, simplify fakeConfig to only include root (e.g., { root: "/project"
} as ResolvedConfig), and update any test callers of createPlugin to the new
signature so they no longer pass or rely on the removed mode argument; keep the
call to (plugin as any).configResolved(fakeConfig) and the function name
createPlugin unchanged.

240-250: Test name "in dev mode" is a slight misnomer after the isDev removal.

The hook no longer has an internal dev-mode guard; it runs whenever Vite invokes it (which is only during serve, thanks to apply: "serve"). The name implies conditional dev-mode behaviour that no longer exists in the hook body.

-  test("returns tag descriptors in dev mode", () => {
+  test("returns tag descriptors when autoImport is enabled", () => {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/vite-plugin.test.ts` around lines 240 - 250, Rename the test to remove
the "in dev mode" wording since isDev was removed: update the test description
string in tests/vite-plugin.test.ts (the test that calls createPlugin() and
invokes (plugin as any).transformIndexHtml()) to something like "returns tag
descriptors" or "returns tag descriptors when invoked", keeping the rest of the
test body unchanged so the assertion targets (createPlugin, transformIndexHtml,
and the tag/attrs/injectTo expectations) remain the same.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tests/vite-plugin.test.ts`:
- Around line 76-80: Remove the duplicate one-line tests that only assert
plugin.apply === "serve" (the test named "skips in production mode (apply:
serve)" and its twin) and instead add a single assertion inside the existing
"plugin metadata" describe block that checks the plugin metadata once; locate
the creation of the plugin via solidGrab() and place
expect(plugin.apply).toBe("serve") in that metadata block so metadata checks are
consolidated and the redundant tests are deleted.
- Around line 6-21: The createPlugin helper has a vestigial mode parameter and
populates fakeConfig.command and fakeConfig.mode which configResolved no longer
consumes; remove the mode parameter from createPlugin, simplify fakeConfig to
only include root (e.g., { root: "/project" } as ResolvedConfig), and update any
test callers of createPlugin to the new signature so they no longer pass or rely
on the removed mode argument; keep the call to (plugin as
any).configResolved(fakeConfig) and the function name createPlugin unchanged.
- Around line 240-250: Rename the test to remove the "in dev mode" wording since
isDev was removed: update the test description string in
tests/vite-plugin.test.ts (the test that calls createPlugin() and invokes
(plugin as any).transformIndexHtml()) to something like "returns tag
descriptors" or "returns tag descriptors when invoked", keeping the rest of the
test body unchanged so the assertion targets (createPlugin, transformIndexHtml,
and the tag/attrs/injectTo expectations) remain the same.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 728b7f3 and 2548ef1.

📒 Files selected for processing (2)
  • src/vite.ts
  • tests/vite-plugin.test.ts

- Move apply: "serve" assertion into plugin metadata describe block
- Remove duplicate one-line apply tests from transform/transformIndexHtml
- Remove vestigial mode parameter from createPlugin helper
- Rename "returns tag descriptors in dev mode" since isDev was removed

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Peyton-Spencer
Peyton-Spencer merged commit d3a6d69 into main Feb 24, 2026
2 checks passed
@Peyton-Spencer
Peyton-Spencer deleted the fix/skip-production-builds branch February 24, 2026 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant